package graph.net.commands;

import graph.net.internal.ServiceLocator;

/**
 * @author amahmood
 *
 */
public class TestAllGraphCommand extends AbstractGraphCommand
{

    /****************************************************************
     * @param serviceLocator
     ***************************************************************/
    protected TestAllGraphCommand(ServiceLocator serviceLocator)
    {
        super(serviceLocator);
    }

    /*************************************************************** 
     * (non-Javadoc)
     * @see graph.net.commands.ICommand#execute(java.lang.String[])
     ***************************************************************/
    @Override
    public String execute(String[] parameters) throws InvalidCommandFormatException, InvalidCommandException,
            IllegalArgumentException, IllegalStateException
    {
        
        GraphCommand graphCommand = new GraphCommand(serviceLocator);
        String result="";
        
        //create test data
       // AddTestDataCommand testDataCommand = new AddTestDataCommand(serviceLocator);
        
       // String result =  testDataCommand.execute(null);
       // serviceLocator.getServiceSession().sendResponse(result);
        
        //find distance
        serviceLocator.getServiceSession().sendResponse("find_distance(a-b-c)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_distance.label(),"a-b-c"));
        serviceLocator.getServiceSession().sendResponse(result);
        
        serviceLocator.getServiceSession().sendResponse("find_distance(a-d)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_distance.label(),"a-d"));
        serviceLocator.getServiceSession().sendResponse(result);
        
        serviceLocator.getServiceSession().sendResponse("find_distance(a-d-c)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_distance.label(),"a-d-c"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        serviceLocator.getServiceSession().sendResponse("find_distance(a-e-b-c-d)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_distance.label(),"a-e-b-c-d"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        serviceLocator.getServiceSession().sendResponse("find_distance(a-e-d)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_distance.label(),"a-e-d"));
        serviceLocator.getServiceSession().sendResponse(result);        
                
        
        //all paths with max stop
        serviceLocator.getServiceSession().sendResponse("find_paths_with_max_stops(c,c,3)");
        result = graphCommand.execute(convertToPrams(3,CommandName.find_paths_with_max_stops.label(),"c", "c"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        //all paths with exact stop
        serviceLocator.getServiceSession().sendResponse("find_paths_with_exact_stops(a,c,4)");
        result = graphCommand.execute(convertToPrams(4,CommandName.find_paths_with_exact_stops.label(),"a", "c"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        //lenght of shortest route
        serviceLocator.getServiceSession().sendResponse("find_shortest_path_length(a,c)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_shortest_path_length.label(),"a", "c"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        serviceLocator.getServiceSession().sendResponse("find_shortest_path_length(b,b)");
        result = graphCommand.execute(convertToPrams(0,CommandName.find_shortest_path_length.label(),"b", "b"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        
        //number of routes
        serviceLocator.getServiceSession().sendResponse("find_all_paths_less_then_distance(c,c, 28)");
        result = graphCommand.execute(convertToPrams(28,CommandName.find_all_paths_less_then_distance.label(),"c", "c"));
        serviceLocator.getServiceSession().sendResponse(result);        
        
        return "Done";
    }
    
    
    /****************************************************************
     * @param arg1
     * @param arg2
     * @param arg3
     * @return
     ***************************************************************/
    private String[] convertToPrams(int arg0, String... arg1)
    {
        String[] out;
        
        if (arg0 > 0)
        {
            out = new String[arg1.length+1];
            out[arg1.length] = Integer.toString(arg0);
        }
        else
        {
            out = new String[arg1.length];
        }
        
        for (int i=0; i < arg1.length; i++)
        {
            out[i]=arg1[i];
        }
        
        return out;
    }

}
